package org.smile.homework01.kevin.Rocket;

public class Flying {
    Engine[] engines;

    public Flying(int i) {
        engines = new Engine[i];
        for (int j = 0; j < 3; j++) {
            engines[j] = new Engine(j + 1);
        }
    }
   public void EngineStatus(){
        for (int i = 0; i < engines.length; i++) {
            this.engines = engines;
            int runtime = engines[i].getRuntime();
            int cdtime = engines[i].getCdtime();
            String name = engines[i].getEngineName();
            System.out.println(name + "运行时间为" +runtime + "冷却时间为" + cdtime);

        }

   }
    public void fashe() {
        int start = 0;
        do {
            int runtime1 = engines[start].getRuntime();
            int cdtime1 = engines[start].getCdtime();
            String name = engines[start].engineName;
            String status = engines[start].getStatus();
            if (!status.equals("standby")) {
                System.out.println("运行结束");
                break;
            }
            System.out.println(name + "开始运行");
            while (true) {
                for (Engine Num : engines) {
                    Num.CoolDown();
                }
                runtime1--;
                System.out.println(name + "运行时间剩余" + runtime1);
                if (runtime1 <= 0) {
                    System.out.println(name + "cooling");
                    engines[start].setCooltime(cdtime1);
                    engines[start].status = ("cooling");
                    break;
                }
            }
            start++;
            if (start == 3) {
                start = 0;
            }

        } while (start < 3);
    }


}
